aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/[username]
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2022-11-02 19:47:29 -0700
committerAdam Soltys <[email protected]>2022-11-02 19:48:18 -0700
commit23ffc5a6359dbc84a1de1da632412edeb9989b5f (patch)
tree1cc276efeb5287e1fc176ec60d46aed091ab08ca /src/routes/(app)/[username]
parentc12857a38eed1227ed51dc6e0af7242e66dd7561 (diff)
downloadcoinos-ui-23ffc5a6359dbc84a1de1da632412edeb9989b5f.tar.gz
coinos-ui-23ffc5a6359dbc84a1de1da632412edeb9989b5f.zip
move to app layout
Diffstat (limited to 'src/routes/(app)/[username]')
-rw-r--r--src/routes/(app)/[username]/+layout.svelte7
-rw-r--r--src/routes/(app)/[username]/+page.server.js6
-rw-r--r--src/routes/(app)/[username]/+page.svelte85
-rw-r--r--src/routes/(app)/[username]/bitcoin/+page.server.js4
-rw-r--r--src/routes/(app)/[username]/bitcoin/+page.svelte0
-rw-r--r--src/routes/(app)/[username]/customers/+page.svelte0
-rw-r--r--src/routes/(app)/[username]/dashboard/+page.server.js1
-rw-r--r--src/routes/(app)/[username]/dashboard/+page.svelte76
-rw-r--r--src/routes/(app)/[username]/receive/+page.server.js5
-rw-r--r--src/routes/(app)/[username]/receive/+page.svelte30
-rw-r--r--src/routes/(app)/[username]/receive/[network]/[amount]/+page.server.js0
-rw-r--r--src/routes/(app)/[username]/receive/[network]/[amount]/+page.svelte1
-rw-r--r--src/routes/(app)/[username]/settings/+page.server.js21
-rw-r--r--src/routes/(app)/[username]/settings/+page.svelte104
-rw-r--r--src/routes/(app)/[username]/settings/_account.svelte255
-rw-r--r--src/routes/(app)/[username]/settings/_pos.svelte27
-rw-r--r--src/routes/(app)/[username]/settings/_security.svelte218
-rw-r--r--src/routes/(app)/[username]/support/+page.server.js13
-rw-r--r--src/routes/(app)/[username]/support/+page.svelte76
-rw-r--r--src/routes/(app)/[username]/transactions/[...page]/+page.server.js24
-rw-r--r--src/routes/(app)/[username]/transactions/[...page]/+page.svelte164
21 files changed, 1117 insertions, 0 deletions
diff --git a/src/routes/(app)/[username]/+layout.svelte b/src/routes/(app)/[username]/+layout.svelte
new file mode 100644
index 00000000..b2efa894
--- /dev/null
+++ b/src/routes/(app)/[username]/+layout.svelte
@@ -0,0 +1,7 @@
+<script>
+ import { AppHeader } from '$comp';
+ export let data;
+</script>
+
+<AppHeader {data} />
+<slot />
diff --git a/src/routes/(app)/[username]/+page.server.js b/src/routes/(app)/[username]/+page.server.js
new file mode 100644
index 00000000..0840161a
--- /dev/null
+++ b/src/routes/(app)/[username]/+page.server.js
@@ -0,0 +1,6 @@
+import { get, post } from '$lib/utils';
+
+export async function load({ params }) {
+ let { username } = params;
+ return get(`/users/${username}`);
+}
diff --git a/src/routes/(app)/[username]/+page.svelte b/src/routes/(app)/[username]/+page.svelte
new file mode 100644
index 00000000..810fb567
--- /dev/null
+++ b/src/routes/(app)/[username]/+page.svelte
@@ -0,0 +1,85 @@
+<script>
+ import { browser } from '$app/environment';
+ import { onMount } from 'svelte';
+ import { Icon, PageNotFound } from '$comp';
+ import { copy } from '$lib/utils';
+ import { t } from '$lib/translations';
+ export let data;
+
+ let { subject } = data;
+
+ let lightningAddress = `${data?.username}@coinos.io`;
+
+ onMount(async () => {
+ if (browser) {
+ let { default: QRCodeStyling } = await import('qr-code-styling');
+ const qrCode = new QRCodeStyling({
+ width: window.screen.width < 640 ? 250 : 300,
+ type: 'canvas',
+ data: lightningAddress,
+ image: '/images/invoice.svg',
+ backgroundOptions: {
+ color: 'rgba(0, 0, 0, 0)'
+ },
+ dotsOptions: {
+ type: 'rounded'
+ },
+ imageOptions: {
+ hideBackgroundDots: false
+ }
+ });
+
+ qrCode.append(document.getElementById('qr'));
+ }
+ });
+
+ let followed = false;
+</script>
+
+<div class="container px-4 flex flex-wrap">
+ <div class="p-10 pt-20">
+ <h1 class="text-3xl font-bold">{subject.username}</h1>
+
+ <p class="text-secondary w-64 mb-4">
+ {subject.address && subject.address !== 'null' ? subject.address : ''}
+ </p>
+
+ <div class="flex gap-2">
+ <button
+ class="border rounded-full py-2 w-28 font-semibold flex justify-center items-center text-sm"
+ on:click={() => (followed = !followed)}
+ ><Icon icon={followed ? 'minus' : 'plus'} style="mr-1" />
+ {$t('user.' + (followed ? 'following' : 'follow'))}
+ </button>
+
+ <a href={`/${subject.username}/receive`}>
+ <button
+ class="border rounded-full py-2 w-28 font-semibold flex justify-center items-center text-sm"
+ >
+ <Icon icon="send" style="mr-1" />
+ Pay
+ </button>
+ </a>
+ </div>
+ </div>
+
+ <div class="space-y-5 md:mt-20 mx-auto w-[350px]">
+ <div
+ on:click={() => copy(lightningAddress)}
+ id="qr"
+ class="cursor-pointer w-[292px] md:w-[342px] h-[342px] border border-lightgrey rounded-3xl flex p-5 justify-center items-center relative mx-auto"
+ />
+
+ <div class="bg-primary font-semibold rounded-xl text-sm p-3 flex justify-between items-center">
+ <span class="mx-auto">{lightningAddress}</span>
+ <button class="hover:opacity-80" on:click={() => copy(lightningAddress)}>
+ <Icon icon="copy" style="ml-2" />
+ </button>
+ </div>
+ <p class="text-center">
+ This is a <a href="https://lightningaddress.com/" class="underline" target="_blank"
+ >lightning address</a
+ >
+ </p>
+ </div>
+</div>
diff --git a/src/routes/(app)/[username]/bitcoin/+page.server.js b/src/routes/(app)/[username]/bitcoin/+page.server.js
new file mode 100644
index 00000000..7ef65346
--- /dev/null
+++ b/src/routes/(app)/[username]/bitcoin/+page.server.js
@@ -0,0 +1,4 @@
+import { redirect } from '@sveltejs/kit';
+export async function load({ params }) {
+ throw redirect(303, `/${params.username}`);
+}
diff --git a/src/routes/(app)/[username]/bitcoin/+page.svelte b/src/routes/(app)/[username]/bitcoin/+page.svelte
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/routes/(app)/[username]/bitcoin/+page.svelte
diff --git a/src/routes/(app)/[username]/customers/+page.svelte b/src/routes/(app)/[username]/customers/+page.svelte
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/routes/(app)/[username]/customers/+page.svelte
diff --git a/src/routes/(app)/[username]/dashboard/+page.server.js b/src/routes/(app)/[username]/dashboard/+page.server.js
new file mode 100644
index 00000000..b6206324
--- /dev/null
+++ b/src/routes/(app)/[username]/dashboard/+page.server.js
@@ -0,0 +1 @@
+export const load = ({ parent }) => parent();
diff --git a/src/routes/(app)/[username]/dashboard/+page.svelte b/src/routes/(app)/[username]/dashboard/+page.svelte
new file mode 100644
index 00000000..160887e3
--- /dev/null
+++ b/src/routes/(app)/[username]/dashboard/+page.svelte
@@ -0,0 +1,76 @@
+<script>
+ import { f, s, post, failure, sats } from '$lib/utils';
+ import { tick } from 'svelte';
+ import { Icon } from '$comp';
+ import { rate, selectedRate } from '$lib/store';
+ import { goto } from '$app/navigation';
+ import { t } from '$lib/translations';
+
+ export let data;
+
+ let ease = (t) => (t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t);
+ let interval;
+
+ $: animateRate($selectedRate);
+ let animateRate = (newRate) => {
+ if (!accountBalanceFiat) return;
+ let t = 0;
+ let newBalance = (user.account.balance * newRate) / sats;
+ let oldBalance = parseFloat(accountBalanceFiat);
+ let diff = oldBalance - newBalance;
+
+ clearInterval(interval);
+ interval = setInterval(() => {
+ let delta = diff * ease(t / 100);
+ accountBalanceFiat = (oldBalance - delta).toFixed(2);
+ if (t > 80) clearInterval(interval);
+ t++;
+ }, 10);
+ };
+
+ $: user = data.user;
+ $: accountBalanceFiat =
+ accountBalanceFiat ||
+ (user && $selectedRate && ((user.account.balance * $selectedRate) / sats).toFixed(2));
+
+ let payreq = '',
+ payreqField,
+ loading;
+
+ $: btcPrice = f($selectedRate, user.currency);
+
+ $: accountBalanceBtc = user.account.balance / sats;
+
+ $: accountBalanceSats = s(user.account.balance);
+</script>
+
+<div class="container px-4 max-w-md mx-auto mt-20">
+ <div class="text-5xl font-bold mb-2">
+ {$selectedRate ? f(accountBalanceFiat, user.currency) : $t('user.dashboard.fetchingRate')}
+ </div>
+
+ <div class="text-secondary text-2xl">
+ {accountBalanceSats} SAT
+ </div>
+
+ <div class="grid sm:grid-cols-2 gap-2 mt-8">
+ <a href={`/${user.username}/receive`}>
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >{$t('user.dashboard.receive')}</button
+ >
+ </a>
+ {#if user.account.balance > 0}
+ <a href="/send">
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >{$t('user.dashboard.withdraw')}</button
+ >
+ </a>
+ {:else}
+ <a href={`/${user.username}/settings`}>
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >Setup Account</button
+ >
+ </a>
+ {/if}
+ </div>
+</div>
diff --git a/src/routes/(app)/[username]/receive/+page.server.js b/src/routes/(app)/[username]/receive/+page.server.js
new file mode 100644
index 00000000..1068f273
--- /dev/null
+++ b/src/routes/(app)/[username]/receive/+page.server.js
@@ -0,0 +1,5 @@
+import invoice from '$lib/invoice';
+
+export const actions = {
+ default: invoice
+};
diff --git a/src/routes/(app)/[username]/receive/+page.svelte b/src/routes/(app)/[username]/receive/+page.svelte
new file mode 100644
index 00000000..11d3a6db
--- /dev/null
+++ b/src/routes/(app)/[username]/receive/+page.svelte
@@ -0,0 +1,30 @@
+<script>
+ import { Icon, Numpad } from '$comp';
+ import { t } from '$lib/translations';
+ import { enhance } from '$app/forms';
+
+ export let data;
+ let amount;
+
+ let { currency, username } = data.subject;
+</script>
+
+<form method="POST" class="flex justify-center items-center mt-24 mb-3 px-3" use:enhance>
+ <input type="hidden" name="amount" value={amount} />
+ <input type="hidden" name="currency" value={currency} />
+ <input type="hidden" name="username" value={username} />
+ <input type="hidden" name="prompt" value="true" />
+
+ <div class="space-y-3 w-full md:w-[300px] mx-auto">
+ <Numpad bind:amount bind:currency />
+ <button
+ type="submit"
+ class="bg-black text-white rounded-xl w-full h-[48px] flex justify-center items-center font-semibold {!amount
+ ? 'opacity-50'
+ : 'opacity-100 hover:opacity-80'}"
+ disabled={!amount}
+ >
+ Next
+ </button>
+ </div>
+</form>
diff --git a/src/routes/(app)/[username]/receive/[network]/[amount]/+page.server.js b/src/routes/(app)/[username]/receive/[network]/[amount]/+page.server.js
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/routes/(app)/[username]/receive/[network]/[amount]/+page.server.js
diff --git a/src/routes/(app)/[username]/receive/[network]/[amount]/+page.svelte b/src/routes/(app)/[username]/receive/[network]/[amount]/+page.svelte
new file mode 100644
index 00000000..45b983be
--- /dev/null
+++ b/src/routes/(app)/[username]/receive/[network]/[amount]/+page.svelte
@@ -0,0 +1 @@
+hi
diff --git a/src/routes/(app)/[username]/settings/+page.server.js b/src/routes/(app)/[username]/settings/+page.server.js
new file mode 100644
index 00000000..ae7e0a78
--- /dev/null
+++ b/src/routes/(app)/[username]/settings/+page.server.js
@@ -0,0 +1,21 @@
+import { invalid } from '@sveltejs/kit';
+import { auth, get, post } from '$lib/utils';
+
+export const actions = {
+ default: async ({ cookies, request }) => {
+ let form = Object.fromEntries(await request.formData());
+
+ let user = {
+ ...(await get('/me', auth(cookies))),
+ ...form
+ };
+
+ try {
+ await post(`/user`, user, auth(cookies));
+ } catch (e) {
+ return invalid(400, { message: e.message });
+ }
+
+ return { success: true };
+ }
+};
diff --git a/src/routes/(app)/[username]/settings/+page.svelte b/src/routes/(app)/[username]/settings/+page.svelte
new file mode 100644
index 00000000..86705b1d
--- /dev/null
+++ b/src/routes/(app)/[username]/settings/+page.svelte
@@ -0,0 +1,104 @@
+<script>
+ import { onMount } from 'svelte';
+ import { fly } from 'svelte/transition';
+ import { enhance } from '$app/forms';
+ import Account from './_account.svelte';
+ import Pos from './_pos.svelte';
+ import Security from './_security.svelte';
+
+ import { Icon, Spinner, Pin } from '$comp';
+ import { t } from '$lib/translations';
+ import { failure, success } from '$lib/utils';
+ import { avatarUpload, bannerUpload, pin } from '$lib/store';
+ import { upload } from '$lib/upload';
+
+ export let data;
+ export let form;
+
+ let { user, rates, token } = data;
+ $: update(data);
+ let update = () => ({ user, rates, token } = data);
+
+ $: if (form?.message?.startsWith('Pin')) {
+ failure('Wrong pin, try again');
+ $pin = '';
+ }
+
+ let tab = 'account';
+
+ let tabs = [
+ { name: 'account', key: 'ACCOUNT', comp: Account },
+ { name: 'pos', key: 'POINT_OF_SALE', comp: Pos },
+ { name: 'security', key: 'SECURITY', comp: Security }
+ ];
+
+ $: ({ comp } = tabs.find((t) => t.name === tab));
+
+ let loading, submit;
+ let save = async (msg) => {
+ loading = true;
+ if (typeof msg !== 'string') msg = 'Settings saved';
+
+ try {
+ if ($avatarUpload) {
+ await upload($avatarUpload.file, $avatarUpload.type, $avatarUpload.progress, token);
+ }
+
+ if ($bannerUpload) {
+ await upload($bannerUpload.file, $bannerUpload.type, $bannerUpload.progress, token);
+ }
+
+ success(msg);
+ } catch (e) {
+ console.log(e);
+ failure('Something went wrong');
+ }
+
+ loading = false;
+ };
+
+ let loaded;
+ onMount(() => setTimeout(() => (loaded = true), 50));
+</script>
+
+{#if loaded && user.haspin && $pin?.length !== 6}
+ <Pin />
+{/if}
+
+<form method="POST" class="mb-[154px]" use:enhance on:submit={save}>
+ <input type="hidden" name="pin" value={$pin} />
+
+ <div class="mt-24 mb-20 px-3 md:px-0 w-full md:w-[400px] mx-auto space-y-8">
+ <h1 class="text-center text-3xl md:text-4xl font-semibold mb-10">
+ {$t('user.settings.header')}
+ </h1>
+
+ <div class="font-bold flex justify-between items-center border-b pb-3 text-secondary">
+ {#each tabs as { name, key }}
+ <button
+ class="hover:opacity-80"
+ class:text-black={tab === name}
+ on:click|preventDefault={() => (tab = name)}>{$t(`user.settings.${key}`)}</button
+ >
+ {/each}
+ </div>
+
+ <svelte:component this={comp} {user} {rates} {submit} />
+ </div>
+ <div
+ class="z-10 fixed bottom-0 bg-white shadow border-t w-full flex justify-center items-center py-3"
+ >
+ <button
+ bind:this={submit}
+ type="submit"
+ class="border-2 border-black rounded-xl font-semibold mx-auto py-3 w-40 hover:opacity-80"
+ class:bg-black={loading}
+ >
+ {#if loading}
+ <Spinner />
+ {:else}
+ <div class="my-auto">Save Settings</div>
+ {/if}
+ </button>
+ </div>
+</form>
diff --git a/src/routes/(app)/[username]/settings/_account.svelte b/src/routes/(app)/[username]/settings/_account.svelte
new file mode 100644
index 00000000..e49205ca
--- /dev/null
+++ b/src/routes/(app)/[username]/settings/_account.svelte
@@ -0,0 +1,255 @@
+<script>
+ import { tick } from 'svelte';
+ import { colorTheme, tempProfileFiles, avatarUpload, bannerUpload } from '$lib/store';
+ import { Icon, Toggle, LocaleSelector } from '$comp';
+ import { t } from '$lib/translations';
+ import { upload } from '$lib/upload';
+
+ export let user;
+
+ let selectedTheme = 1;
+ let revealPassword = false;
+ let password;
+ let profileFile;
+ let select = (type) => files[type].el.click();
+
+ $: profile = files.profile.src;
+ $: banner = files.banner.src;
+ $: $tempProfileFiles = { profile: files.profile.src, banner: files.banner.src };
+
+ let togglePassword = () => (revealPassword = !revealPassword);
+ let colorThemes = [
+ { theme: 1, color1: 'from-[#F5F7FA]', color2: 'to-[#C3CFE2]' },
+ { theme: 2, color1: 'from-[#FDFCFB]', color2: 'to-[#E2D1C3]' },
+ { theme: 3, color1: 'from-[#E6E9F0]', color2: 'to-[#EEF1F5]' },
+ { theme: 4, color1: 'from-[#D5D4D0]', color2: 'to-[#EEEEEC]' },
+ { theme: 5, color1: 'from-[#F3E7E9]', color2: 'to-[#E3EEFF]' },
+ { theme: 6, color1: 'from-[#F5F7FA]', color2: 'via-[#EAF2FF] to-[#DEDFFF]' }
+ ];
+
+ let handleThemeClick = (colors) => {
+ selectedTheme = colors.theme;
+ $colorTheme = colors.color1 + ' ' + colors.color2;
+ };
+
+ let percent;
+ let progress = async (event) => {
+ percent = Math.round((event.loaded / event.total) * 100);
+ };
+
+ let tooLarge = {};
+
+ let files = { profile: {}, banner: {} };
+ let handleFile = async ({ target }, type) => {
+ tooLarge[type] = false;
+ let file = target.files[0];
+ if (file.size > 10000000) return (tooLarge[type] = true);
+ var reader = new FileReader();
+ reader.onload = async (e) => {
+ files[type].src = e.target.result;
+ };
+ reader.readAsDataURL(file);
+
+ files[type].filename = file.name;
+ if (type === 'profile') {
+ $avatarUpload = { file, type, progress };
+ } else if (type === 'banner') {
+ $bannerUpload = { file, type, progress };
+ }
+ };
+
+ $: user.password = user.confirm = password;
+</script>
+
+<div>
+ <label for="language" class="font-bold block mb-1">{$t('user.settings.locale')}</label>
+ <LocaleSelector style="select-styles block py-3 w-full" />
+</div>
+
+<!-- TODO
+<div>
+ <label for="email" class="font-bold mb-1 block">{$t('user.settings.email')}</label>
+ <input type="email" name="email" bind:value={user.email} />
+</div> -->
+
+<!-- TODO fix breaking changes when user updates this field -->
+<div>
+ <label for="username" class="font-bold mb-1 block">{$t('user.settings.username')}</label>
+ <input disabled type="text" name="username" bind:value={user.username} />
+ <input type="hidden" name="username" bind:value={user.username} />
+</div>
+
+<div class="relative">
+ <label for="password" class="block font-bold block mb-1">{$t('user.settings.newPassword')}</label>
+ {#if revealPassword}
+ <input name="password" type="text" bind:value={password} />
+ {:else}
+ <input name="password" type="password" bind:value={password} />
+ {/if}
+ <button
+ type="button"
+ on:click={togglePassword}
+ on:keydown={togglePassword}
+ class="absolute right-5 top-11"
+ >
+ <Icon icon={revealPassword ? 'eye' : 'eye-off'} />
+ </button>
+</div>
+
+<div>
+ <label for="address" class="font-bold mb-1 block">{$t('user.settings.businessAddress')}</label>
+ <input type="text" name="address" bind:value={user.address} />
+</div>
+
+<!-- TODO -->
+<!-- <div> -->
+<!-- <div class="flex justify-between items-center"> -->
+<!-- <span class="font-bold">{$t('user.settings.emailNotifications')}</span> -->
+<!-- <Toggle id="email-notify" /> -->
+<!-- </div> -->
+<!-- <p class="text-secondary mt-1 w-9/12"> -->
+<!-- {$t('user.settings.emailNotificationsDescription')} -->
+<!-- </p> -->
+<!-- </div> -->
+<!-- -->
+<!-- <div> -->
+<!-- <div class="flex justify-between items-center"> -->
+<!-- <span class="font-bold">{$t('user.settings.smsNotifications')}</span> -->
+<!-- <Toggle id="sms-notify" /> -->
+<!-- </div> -->
+<!-- <p class="text-secondary mt-1 w-9/12"> -->
+<!-- {$t('user.settings.smsNotificationsDescription')} -->
+<!-- </p> -->
+<!-- </div> -->
+
+<div>
+ <span class="font-bold">{$t('user.settings.profileImage')}</span>
+
+ <div class="flex">
+ {#if profile}
+ <div
+ class="relative rounded-full overflow-hidden text-center w-20 h-20 my-auto hover:opacity-80 cursor-pointer"
+ on:click={() => select('profile')}
+ on:keydown={() => select('profile')}
+ >
+ <img
+ src={profile}
+ class="absolute w-full h-full object-cover object-center visible overflow-hidden"
+ alt={user.username}
+ />
+ </div>
+ {:else if user.profile}
+ <div
+ class="relative rounded-full overflow-hidden text-center w-20 h-20 my-auto hover:opacity-80 cursor-pointer"
+ on:click={() => select('profile')}
+ on:keydown={() => select('profile')}
+ >
+ <img
+ src={`/api/public/${user.username}-profile.webp`}
+ class="absolute w-full h-full object-cover object-center visible overflow-hidden"
+ alt={user.username}
+ />
+ </div>
+ {:else}
+ <div
+ class="rounded-full border-4 border-white p-4 bg-gradient-to-r {$colorTheme} w-24 my-auto hover:opacity-80 cursor-pointer"
+ on:click={() => select('profile')}
+ on:keydown={() => select('profile')}
+ >
+ <Icon icon="logo-symbol-white" style="mx-auto" />
+ </div>
+ {/if}
+ <div class="ml-2 p-2">
+ <!-- found missing translation -->
+ <button
+ type="button"
+ class="border rounded-2xl font-bold w-24 text-center px-0 py-2 hover:opacity-80"
+ on:click={() => select('profile')}
+ on:keydown={() => select('profile')}>Select</button
+ >
+ <input
+ type="file"
+ class="hidden"
+ bind:this={files.profile.el}
+ on:change={(e) => handleFile(e, 'profile')}
+ />
+ {#if files.profile.filename}
+ <div class="mt-2 text-sm">{files.profile.filename}</div>
+ {/if}
+ </div>
+ </div>
+
+ {#if tooLarge['profile']}
+ <div class="text-red-600">Max file size 10MB</div>
+ {/if}
+</div>
+
+<div>
+ <div class="flex justify-between items-center">
+ <span class="font-bold">{$t('user.settings.bannerImage')}</span>
+ </div>
+ <!-- found missing translation -->
+
+ {#if banner}
+ <img
+ src={banner}
+ class="w-full object-cover object-center visible overflow-hidden h-48 mb-4 hover:opacity-80"
+ on:click={() => select('banner')}
+ on:keydown={() => select('banner')}
+ alt="Banner"
+ />
+ {:else if user.banner}
+ <img
+ src={`/api/public/${user.username}-banner.webp`}
+ class="w-full object-cover object-center visible overflow-hidden h-48 mb-4 hover:opacity-80"
+ on:click={() => select('banner')}
+ on:keydown={() => select('banner')}
+ alt="Banner"
+ />
+ {:else}
+ <div
+ class="bg-gradient-to-r {$colorTheme} w-full h-48 mb-4 cursor-pointer hover:opacity-80"
+ on:click={() => select('banner')}
+ on:keydown={() => select('banner')}
+ alt="Banner"
+ />
+ {/if}
+
+ <!-- found missing translation -->
+ <button
+ type="button"
+ class="border rounded-2xl font-bold w-24 text-center px-0 py-2 hover:opacity-80"
+ on:click={() => select('banner')}
+ on:keydown={() => select('banner')}>Select</button
+ >
+ <input
+ type="file"
+ class="hidden"
+ bind:this={files.banner.el}
+ on:change={(e) => handleFile(e, 'banner')}
+ />
+ {#if files.banner.filename}
+ <div class="mt-2 text-sm">{files.banner.filename}</div>
+ {/if}
+
+ {#if tooLarge['banner']}
+ <div class="text-red-600">Max file size 10MB</div>
+ {/if}
+</div>
+
+<!-- TODO
+<div>
+ <span class="font-bold mb-1 block">{$t('user.settings.theme')}</span>
+ <p class="text-secondary mb-1">{$t('user.settings.themeDescription')}</p>
+ {#each colorThemes as colors}
+ <button
+ type="button"
+ class="hover:opacity-80 mr-2 w-10 h-10 bg-gradient-to-r {colors.color1} {colors.color2} rounded-xl border-2 {selectedTheme ===
+ colors.theme
+ ? 'border-black'
+ : ''}"
+ on:click={() => handleThemeClick(colors)}
+ on:keydown={() => handleThemeClick(colors)}
+ />
+ {/each}
+</div> -->
diff --git a/src/routes/(app)/[username]/settings/_pos.svelte b/src/routes/(app)/[username]/settings/_pos.svelte
new file mode 100644
index 00000000..cf4a5ece
--- /dev/null
+++ b/src/routes/(app)/[username]/settings/_pos.svelte
@@ -0,0 +1,27 @@
+<script>
+ import { Icon, Toggle } from '$comp';
+ import { t } from '$lib/translations';
+ import { success, failure } from '$lib/utils';
+
+ export let rates, user;
+
+ const fiats = Object.keys(rates);
+</script>
+
+<div>
+ <label for="currency" class="font-bold block mb-1">{$t('user.settings.localCurrency')}</label>
+ <select name="currency" class="select-styles block py-3 w-full">
+ {#each fiats as fiat}
+ <option value={fiat} selected={user.currency === fiat}>{fiat}</option>
+ {/each}
+ </select>
+</div>
+
+<!-- TODO
+<div>
+ <label for="unit" class="font-bold block mb-1">{$t('user.settings.btcUnit')}</label>
+ <select disabled name="unit" class="select-styles block py-3 w-full" bind:value={user.unit}>
+ <option value="SAT">{$t('user.settings.satoshis')} (SAT)</option>
+ <option value="BTC">{$t('user.settings.bitcoin')} (BTC)</option>
+ </select>
+</div> -->
diff --git a/src/routes/(app)/[username]/settings/_security.svelte b/src/routes/(app)/[username]/settings/_security.svelte
new file mode 100644
index 00000000..98b9b503
--- /dev/null
+++ b/src/routes/(app)/[username]/settings/_security.svelte
@@ -0,0 +1,218 @@
+<script>
+ import { tick } from 'svelte';
+ import { t } from '$lib/translations';
+ import { Icon, Qr } from '$comp';
+ import { Pincode, PincodeInput } from 'svelte-pincode';
+ import { post, success, failure } from '$lib/utils';
+ import { pin as current } from '$lib/store';
+
+ export let user, submit;
+
+ let settingPin, setting2fa, disabling2fa;
+
+ let token = '';
+ let pinCode = [];
+ let verifyCode = [];
+ let tokenInput, pinInput, verifyInput;
+ let verifying = false;
+ let old;
+
+ let startVerifying = () => {
+ verifying = true;
+ };
+
+ $: pin = pinCode.join('');
+
+ let locked;
+ $: verifyCode.join('').length > 5 && checkPin();
+ let checkPin = async () => {
+ old = $current;
+ if (locked) return;
+ locked = true;
+
+ let verify = verifyCode.join('');
+
+ pinCode = ['', '', '', '', '', ''];
+ verifyCode = ['', '', '', '', '', ''];
+ settingPin = false;
+
+ try {
+ if (pin.length > 5 && pin === verify) {
+ user.haspin = true;
+ $current = pin;
+ submit.click();
+ } else {
+ failure('Pin mismatch, try again');
+ settingPin = true;
+ pinInput.focusFirstInput();
+ }
+ } catch (e) {
+ failure('Problem setting PIN');
+ }
+
+ verifying = false;
+
+ await new Promise((r) => setTimeout(r, 500));
+ locked = false;
+ };
+
+ $: if (verifying) verifyInput && tick().then(verifyInput.focusFirstInput);
+ $: if (settingPin) pinInput && tick().then(pinInput.focusFirstInput);
+ $: if (setting2fa || disabling2fa) tokenInput && tick().then(tokenInput?.focusFirstInput);
+
+ let reset = () => {
+ token = '';
+ return true;
+ };
+
+ let togglePin = async () => {
+ if (user.haspin) {
+ try {
+ pin = null;
+ submit.click();
+ } catch (e) {
+ failure('Failed to disable pin');
+ }
+ } else {
+ settingPin = true;
+ }
+ };
+
+ let toggleEnabling = () => reset() && (setting2fa = !setting2fa);
+ let toggleDisabling = () => reset() && (disabling2fa = !disabling2fa);
+
+ $: enable2fa(token);
+ let enable2fa = async (twoFa) => {
+ try {
+ if (setting2fa && token.length === 6) {
+ await post('/enable2fa', { token });
+ success('2FA enabled');
+ user.twofa = 1;
+ toggleEnabling();
+ }
+ } catch (e) {
+ failure('Failed to enable 2FA, try again');
+ }
+ };
+
+ $: disable2fa(token);
+ let disable2fa = async () => {
+ try {
+ if (disabling2fa && token.length === 6) {
+ await post('/disable2fa', { token });
+ success('2FA disabled');
+ user.twofa = 0;
+ toggleDisabling();
+ }
+ } catch (e) {
+ failure('Failed to disable 2FA, try again');
+ }
+ };
+
+ $: otpUri = `otpauth://totp/coinos:${user.username}?secret=${user.otpsecret}&period=30&digits=6&algorithm=SHA1&issuer=coinos`;
+</script>
+
+<div>
+ <input type="hidden" name="newpin" value={pin} />
+
+ <span class="font-bold mb-1">{verifying ? 'Verify' : 'Security'} PIN</span>
+ <p class="text-secondary mb-1">
+ {$t('user.settings.securityPINDescription')}
+ </p>
+ {#if settingPin}
+ <div class="flex my-4">
+ <div class="mx-auto">
+ <div class:hidden={verifying}>
+ <Pincode on:complete={startVerifying} bind:code={pinCode} bind:this={pinInput}>
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ </Pincode>
+ </div>
+ <div class:hidden={!verifying}>
+ <Pincode bind:code={verifyCode} bind:this={verifyInput}>
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ </Pincode>
+ </div>
+ </div>
+ </div>
+ {:else}
+ <button type="button" class="primary" on:click={togglePin}
+ ><Icon icon="lock" style="mr-1" /> {user.haspin ? 'Disable Pin' : 'Enable Pin'}</button
+ >
+ {/if}
+</div>
+
+<!-- TODO
+<div>
+ <label for="auto-lock" class="font-bold mb-1">{$t('user.settings.autoLock')}</label>
+ <p class="text-secondary mb-1">
+ {$t('user.settings.autoLockDescription')}
+ </p>
+ <select name="auto-lock" class="select-styles block py-3 w-full">
+ <option value="5">5 min</option>
+ <option value="10">10 min</option>
+ <option value="30">30 min</option>
+ <option value="60">1 h</option>
+ <option value="480">8 h</option>
+ </select>
+</div> -->
+
+<div>
+ <span class="font-bold mb-1">{$t('user.settings.twofa')}</span>
+ <p class="text-secondary mb-4">
+ {$t('user.settings.twofaDescription')}
+ </p>
+ {#if setting2fa}
+ <a href={otpUri}>
+ <Qr text={otpUri} />
+ </a>
+
+ <div class="text-center my-4">
+ {$t('user.settings.accountId')}<br />
+ <b>{user.otpsecret}</b>
+ </div>
+
+ <div class="text-center my-4">
+ {$t('user.settings.oneTimeCode')}<br />
+ <Pincode bind:value={token} bind:this={tokenInput}>
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ </Pincode>
+ </div>
+ {:else if disabling2fa}
+ <div class="text-center my-4">
+ {$t('user.settings.oneTimeCode')}<br />
+ <Pincode bind:value={token} bind:this={tokenInput}>
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ <PincodeInput />
+ </Pincode>
+ </div>
+ {:else if user.twofa}
+ <button type="button" class="primary" on:click={toggleDisabling}>
+ <Icon icon="mobile" style="mr-1" />
+ {$t('user.settings.twofaDisable')}
+ </button>
+ {:else}
+ <button type="button" class="primary" on:click={toggleEnabling}>
+ <Icon icon="mobile" style="mr-1" />
+ {$t('user.settings.twofaSetup')}
+ </button>
+ {/if}
+</div>
diff --git a/src/routes/(app)/[username]/support/+page.server.js b/src/routes/(app)/[username]/support/+page.server.js
new file mode 100644
index 00000000..a335ec96
--- /dev/null
+++ b/src/routes/(app)/[username]/support/+page.server.js
@@ -0,0 +1,13 @@
+export const actions = {
+ default: async ({ cookies, request }) => {
+ let form = Object.fromEntries(await request.formData());
+
+ try {
+ await post('/email', form);
+ } catch (e) {
+ return invalid(400, { failed: true });
+ }
+
+ return { success: true };
+ }
+};
diff --git a/src/routes/(app)/[username]/support/+page.svelte b/src/routes/(app)/[username]/support/+page.svelte
new file mode 100644
index 00000000..cd1cc69f
--- /dev/null
+++ b/src/routes/(app)/[username]/support/+page.svelte
@@ -0,0 +1,76 @@
+<script>
+ import { enhance } from '$app/forms';
+ import { scale } from 'svelte/transition';
+ import { Icon } from '$comp';
+ import { t } from '$lib/translations';
+
+ export let data, form;
+
+ let { user } = data;
+ let email;
+ let message;
+</script>
+
+<div class="container px-4 max-w-lg mx-auto mt-20">
+ {#if form?.success}
+ <h1 class="text-center text-3xl md:text-4xl font-semibold mb-8">Thank you!</h1>
+ <p class="text-center mb-8">Someone will be in touch shortly.</p>
+
+ <a href={`/${user.username}/dashboard`}>
+ <button class="rounded-full border py-2 px-5 font-bold hover:opacity-80 w-full mb-2"
+ >Done</button
+ >
+ </a>
+ {:else}
+ <h1 class="text-center text-3xl md:text-4xl font-semibold mb-8">
+ {$t('user.support.header')}
+ </h1>
+ <form method="POST" use:enhance>
+ <div class="mb-4">
+ <label for="account" class="font-semibold">{$t('user.support.accountName')}</label>
+ <input
+ class="block border rounded-xl p-2 w-full"
+ type="text"
+ name="account"
+ required
+ disabled
+ value={user.username}
+ />
+ </div>
+
+ <div class="mb-4">
+ <label for="email" class="font-semibold">{$t('user.support.email')}</label>
+ <input
+ class="block border rounded-xl p-2 w-full"
+ type="email"
+ name="email"
+ bind:value={email}
+ required
+ />
+ </div>
+
+ <div class="mb-4">
+ <label for="message" class="font-semibold">{$t('user.support.message')}</label>
+ <textarea
+ rows={5}
+ class="block border rounded-xl p-2 w-full"
+ type="text"
+ name="message"
+ bind:value={message}
+ required
+ />
+ </div>
+
+ <button
+ type="submit"
+ disabled={!email || !message}
+ class="{!email || !message
+ ? 'opacity-50'
+ : 'opacity-100'} bg-black text-white font-bold rounded-xl py-3 w-full mx-auto {email &&
+ message
+ ? 'hover:opacity-80'
+ : ''}">{$t('user.support.send')}</button
+ >
+ </form>
+ {/if}
+</div>
diff --git a/src/routes/(app)/[username]/transactions/[...page]/+page.server.js b/src/routes/(app)/[username]/transactions/[...page]/+page.server.js
new file mode 100644
index 00000000..6883dfa9
--- /dev/null
+++ b/src/routes/(app)/[username]/transactions/[...page]/+page.server.js
@@ -0,0 +1,24 @@
+import { get, auth } from '$lib/utils';
+
+let limit = 25;
+
+export async function load({ cookies, params, request }) {
+ let parts = params.page.split('/');
+
+ let start, end, page;
+ if (parts.length === 1) [page] = parts;
+ if (parts.length === 2) [start, page] = parts;
+ if (parts.length === 3) [start, end, page] = parts;
+ if (!parseInt(page)) page = 1;
+
+ let offset = (page - 1) * limit;
+ if (!start) start = Date.now() / 1000 - 24 * 60 * 60;
+
+ let url = `/payments?v2=true&start=${start * 1000}&limit=${limit}&offset=${offset}`;
+ if (end) url += `&end=${end * 1000}`;
+
+ let { total, transactions } = await get(url, auth(cookies));
+ let pages = new Array(Math.ceil(total / limit));
+
+ return { total, transactions, page, pages, start, end };
+}
diff --git a/src/routes/(app)/[username]/transactions/[...page]/+page.svelte b/src/routes/(app)/[username]/transactions/[...page]/+page.svelte
new file mode 100644
index 00000000..dd58509a
--- /dev/null
+++ b/src/routes/(app)/[username]/transactions/[...page]/+page.svelte
@@ -0,0 +1,164 @@
+<script>
+ import { Icon } from '$comp';
+ import { onMount } from 'svelte';
+ import { formatDistance, parseISO } from 'date-fns';
+ import { newPayment } from '$lib/store';
+ import { t } from '$lib/translations';
+ import { f, s, sats } from '$lib/utils';
+ import { page } from '$app/stores';
+ import { differenceInDays, getUnixTime, sub } from 'date-fns';
+ import { goto } from '$app/navigation';
+
+ export let data;
+
+ let { start, end, user } = data;
+ let change = ({ target: { value } }) => goto(value);
+
+ let presets = [
+ { title: 'Today', start: null, end: null },
+ { title: 'Week', start: sub(new Date(), { days: 7 }), end: null },
+ { title: 'Month', start: sub(new Date(), { months: 1 }), end: null },
+ { title: 'All', start: sub(new Date(), { years: 5 }), end: null }
+ ];
+
+ $: selection = start
+ ? presets.findIndex((p) => Math.abs(differenceInDays(new Date(start * 1000), p.start)) < 1)
+ : 0;
+
+ let p,
+ total,
+ transactions = [],
+ pages = [];
+ $: data && ({ page: p, pages, start, end, total, transactions } = data);
+
+ $: $page && ($newPayment = false);
+ $: $newPayment && invalidate(`/users/${user.username}`);
+
+ $: path = $page.url.pathname.substring(0, $page.url.pathname.lastIndexOf('/'));
+ $: console.log(path);
+
+ let csv = () => {
+ const keys = ['hash', 'updatedAt', 'rate', 'currency', 'amount', 'fee', 'tip'];
+ const csv =
+ keys.map((k) => `"${k}"`).join(',') +
+ '\n' +
+ transactions.map((r) => keys.map((k) => `"${r[k]}"`).join(',')).join('\n');
+
+ const filename = 'transactions.csv';
+ let blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
+ if (navigator.msSaveBlob) {
+ navigator.msSaveBlob(blob, filename);
+ } else {
+ let link = document.createElement('a');
+ if (link.download !== undefined) {
+ let url = URL.createObjectURL(blob);
+ link.setAttribute('href', url);
+ link.setAttribute('download', filename);
+ link.style.visibility = 'hidden';
+ document.body.appendChild(link);
+ link.click();
+ document.body.removeChild(link);
+ }
+ }
+ };
+</script>
+
+<div class="mt-24 mb-20">
+ <h1 class="px-3 md:px-0 text-center text-3xl md:text-4xl font-semibold mb-10">
+ {$t('user.transactions.header')}
+ </h1>
+
+ <div class="container w-full mx-auto md:text-lg px-4 max-w-xl">
+ <div class="flex text-md text-secondary flex-wrap mb-4">
+ <select class="md:hidden bg-white border p-4 rounded-full" on:change={change}>
+ {#each presets as { start, end, title }, i}
+ <option
+ selected={selection === i}
+ value={`/${user.username}/transactions/${start ? getUnixTime(start) + '/' : ''}1`}
+ >{title}</option
+ >
+ {/each}
+ </select>
+ <div class="hidden md:block flex flex-wrap gap-2">
+ {#each presets as { start, end, title }, i}
+ <a
+ class:active={selection === i}
+ href={`/${user.username}/transactions/${start ? getUnixTime(start) + '/' : ''}1`}
+ >
+ <button class="rounded-full border py-2 px-5 hover:opacity-80 mb-2">
+ <div class="my-auto">{title}</div>
+ </button>
+ </a>
+ {/each}
+ </div>
+ <button class="ml-auto rounded-xl border py-2 px-5 hover:opacity-80 mb-2 flex" on:click={csv}>
+ <Icon icon="save" style="opacity-50 mr-2" />
+ <div class="my-auto">Export</div>
+ </button>
+ </div>
+
+ <div class="flex flex-wrap justify-center mb-8">
+ {#if pages.length > 1}
+ {#each pages as _, i}
+ <a class="mr-1 last:mr-0" href={`${path}/${i + 1}`} class:active={parseInt(p) === i + 1}>
+ <div class="border py-2 rounded-full border-2 w-12 h-12 hover:opacity-80 text-center">
+ {i + 1}
+ </div>
+ </a>
+ {/each}
+ {/if}
+ </div>
+
+ <div class="text-secondary grid grid-cols-3 mb-5">
+ <h2>{$t('user.transactions.AMOUNT')}</h2>
+ <h2 class="text-center" />
+ <h2 class="text-right">{$t('user.transactions.TIME')}</h2>
+ </div>
+
+ <div class="space-y-10">
+ {#if transactions.length}
+ {#each transactions as tx}
+ <div class="grid grid-cols-3 border-b pb-5">
+ <div class="font-bold">
+ <span class="block mb-1"
+ >{tx.amount > 0 ? '+' : ''}{f(tx.amount * (tx.rate / sats), tx.currency)}
+ </span>
+
+ <span class="text-secondary"
+ >{tx.amount > 0 ? '+' : ''}{s(tx.amount)}
+ SAT
+ </span>
+ </div>
+
+ <div class="text-center">
+ <span class="text-secondary"
+ >{$t('user.transactions.' + (tx.amount < 0 ? 'sent' : 'received'))}</span
+ >
+ </div>
+
+ <div class="text-secondary text-right">
+ {formatDistance(parseISO(tx.createdAt), new Date(), {
+ includeSeconds: true,
+ addSuffix: true
+ })}
+ </div>
+ </div>
+ {/each}
+ {:else}
+ <p class="text-secondary text-lg text-center">{$t('user.transactions.empty')}</p>
+ {/if}
+ </div>
+ </div>
+</div>
+
+<style>
+ .active * {
+ @apply bg-black text-white border-black;
+ }
+
+ select {
+ -webkit-appearance: none;
+ -moz-appearance: none;
+ appearance: none;
+ }
+</style>